<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Specifying a Berkeley DB schema using SQL DDL</title>
    <link rel="stylesheet" href="gettingStarted.css" type="text/css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
    <link rel="start" href="index.html" title="Berkeley DB Programmer's Reference Guide" />
    <link rel="up" href="am_misc.html" title="Chapter 4.  Access Method Wrapup" />
    <link rel="prev" href="am_misc_diskspace.html" title="Disk space requirements" />
    <link rel="next" href="am_misc_tune.html" title="Access method tuning" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">Specifying a Berkeley DB schema using SQL DDL</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="am_misc_diskspace.html">Prev</a> </td>
          <th width="60%" align="center">Chapter 4. 
		Access Method Wrapup
        </th>
          <td width="20%" align="right"> <a accesskey="n" href="am_misc_tune.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="sect1" lang="en" xml:lang="en">
      <div class="titlepage">
        <div>
          <div>
            <h2 class="title" style="clear: both"><a id="am_misc_db_sql"></a>Specifying a Berkeley DB schema using SQL DDL</h2>
          </div>
        </div>
      </div>
      <p>
        When starting a new Berkeley DB project, much of the code that you
        must write is dedicated to defining the BDB environment: what
        databases it contains, the types of the databases, and so forth.
        Also, since records in BDB are just byte arrays, you must write
        code that assembles and interprets these byte arrays.
    </p>
      <p>
        Much of this code can be written automatically (in C) by the 
        <a href="../api_reference/C/db_sql.html" class="olink">db_sql utility</a>.  To use it, you first specify the schema of your Berkeley
        DB environment in SQL Data Definition Language (DDL).  Then you
        invoke the db_sql command, giving the DDL as input.  
        <span class="command"><strong>db_sql</strong></span> reads the DDL, and writes C code that 
        implements a storage-layer API suggested by the DDL.
    </p>
      <p>
        The generated API includes a general-purpose initialization
        function, which sets up the environment and the databases (creating
        them if they don't already exist).  It also includes C structure
        declarations for each record type, and numerous specialized
        functions for storing and retrieving those records.
    </p>
      <p>
        <span class="command"><strong>db_sql</strong></span> can also produce a simple test program
        that exercises the generated API.  This program is useful as an
        example of how to use the API.  It contains calls to all of the
        interface functions, along with commentary explaining what the code
        is doing.
    </p>
      <p>
        Once the storage layer API is produced, your application may use it
        as is, or you may customize it as much as you like by editing the
        generated source code.  Be warned, however:
        <span class="command"><strong>db_sql</strong></span> is a one-way process; there is no way to
        automatically incorporate customizations into newly generated code,
        if you decide to run <span class="command"><strong>db_sql</strong></span> again.
    </p>
      <p>
        To learn more about <span class="command"><strong>db_sql</strong></span>, please consult the
        <a href="../api_reference/C/db_sql.html" class="olink">db_sql utility</a> manual page in the Berkeley DB C API guide.
    </p>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="am_misc_diskspace.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="am_misc.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="am_misc_tune.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">Disk space requirements </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> Access method tuning</td>
        </tr>
      </table>
    </div>
  </body>
</html>
